package com.tarena.lbs.activity.controller;

import com.tarena.lbs.activity.pojo.param.ActivityAddParam;
import com.tarena.lbs.activity.pojo.query.ActivityQuery;
import com.tarena.lbs.activity.pojo.vo.ActivityVO;
import com.tarena.lbs.activity.service.ActivityService;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.List;

/**
 * 活动相关功能接口
 */
@RestController
@Tag(name = "活动服务", description = "活动服务")
public class ActivityController {

    private static final Logger log = LoggerFactory.getLogger(ActivityController.class);
    @Autowired
    private ActivityService activityService;


    @Operation(summary = "商家活动列表")
    @PostMapping("/admin/marketing/marketingActivity/info/list")
    public Result<PageResult<ActivityVO>> pageList(ActivityQuery  query)
        throws BusinessException {
        log.info("商家活动列表入参{}", query);
        List<ActivityVO> listVO = activityService.pageList(query);
        PageResult resultPage = new PageResult();
        resultPage.setObjects(listVO);
        resultPage.setTotal(1L);
        resultPage.setPageNo(1);
        resultPage.setPageSize(10);
        return new Result<>(resultPage);
    }

    @Operation(summary = "商家活动保存")
    @PostMapping("/admin/marketing/marketingActivity/info/save")
    public Result<Void> activitySave(@RequestBody ActivityAddParam param)
            throws BusinessException, ParseException {
        log.info("商家活动保存入参{}", param);
        activityService.activitySave(param);
        return Result.success();
    }

    @Operation(summary = "商家活动详情")
    @GetMapping("/admin/marketing/marketingActivity/info/detail/{id}")
    public Result<ActivityVO> activityDetail(@PathVariable("id") Integer id)
        throws BusinessException {
        log.info("商家活动详情入参{}", id);
        ActivityVO activityVO = activityService.activityDetail(id);
        return new Result<>(activityVO);
    }

    @Operation(summary = "商家活动删除")
    @PostMapping("/admin/marketing/marketingActivity/info/delete/{id}")
    public Result<Void> activityDelete(@PathVariable("id") Integer id)
        throws BusinessException {
        log.info("商家活动删除入参{}", id);
        activityService.activityDelete(id);
        return Result.success();
    }

}
